package com.medi.chats.utils;

import org.springframework.stereotype.Service;

@Service
public class UtilsService {

    public String Object2String(Object object) {
        return (object == null) ? "" : object.toString();
    }

    public int Object2Int(Object object) {
        try {
            return (object == null) ? 0 : Integer.parseInt(object.toString());
        }
        catch (Exception e) {
            return 0;
        }
    }

    public long Object2Long(Object object) {
        try {
            return (object == null ||  object.toString().isEmpty() || object.toString().toUpperCase().equals("NULL")) ? 0 : Long.parseLong(object.toString());
        }
        catch (Exception e) {
            return 0;
        }
    }

    public double Object2Double(Object object) {
        try {
            return (object == null || object.toString().isEmpty() || object.toString().toUpperCase().equals("NULL")) ? 0 : Double.parseDouble(object.toString());
        }
        catch (Exception e) {
            return 0;
        }
    }

}
